﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using NHibernate.Properties;

namespace IISDeploy.Data.Interceptor
{
    public class ReflectionOptimizer : NHibernate.Bytecode.Lightweight.ReflectionOptimizer
    {
        private readonly IUnityContainer container;

        public ReflectionOptimizer(IUnityContainer container, Type mappedType, IGetter[] getters, ISetter[] setters)
            : base(mappedType, getters, setters)
        {
            this.container = container;
        }

        public override object CreateInstance()
        {
            object obj = container.Resolve(mappedType);
            if (obj != null)
                return obj;
            else
                return base.CreateInstance();
        }

        protected override void ThrowExceptionForNoDefaultCtor(Type type)
        {
        }
    }
}
